/*********************************************************
*  @file    cm_gnss_demo.c
*  @brief   ML302 OpenCPU GNSS demo file
*  Copyright (c) 2019 China Mobile IOT.
*  All rights reserved.
*  created by yuyangyi 2020/01/08
********************************************************/
#ifdef CM_GNSS_SUPPORT
#include "cm_main.h"
#include "cm_gnss.h"

void cm_test_lbs(void)
{
    char *cellloc = (char *)malloc(50);
    if (cellloc == NULL)
    {
        return;
    }
    memset(cellloc, 0, sizeof(cellloc));
    cm_lbs_getlocation(cellloc);
    cm_printf("LBS:%s\n", cellloc);
    cm_sys_log("LBS:%s", cellloc);
    free(cellloc);
    return;
}

void cm_test_gnss_enable(void)
{
    cm_gnss_enable(1);
    
    return;
}

void cm_test_gnss_getlocateinfo(void)
{
    char *Longitude = (char *)malloc(50);
    if (Longitude == NULL)
    {
        return;
    }
    memset(Longitude, 0, sizeof(Longitude));

    char *Latitude = (char *)malloc(50);
    if (Latitude == NULL)
    {
        return;
    }
    memset(Latitude, 0, sizeof(Latitude));

    char *Altitude = (char *)malloc(50);
    if (Altitude == NULL)
    {
        return;
    }
    memset(Altitude, 0, sizeof(Altitude));

    char *SpeedStr = (char *)malloc(50);
    if (SpeedStr == NULL)
    {
        return;
    }
    memset(SpeedStr, 0, sizeof(SpeedStr));

    char *CntOfSatFix = (char *)malloc(50);
    if (CntOfSatFix == NULL)
    {
        return;
    }
    memset(CntOfSatFix, 0, sizeof(CntOfSatFix));

    if(cm_gnss_getlocateinfo(Longitude, Latitude, Altitude, SpeedStr, CntOfSatFix))
    {
        cm_printf("GNSS getlocateinfo:%s, %s, %s, %s, %s\n", Longitude, Latitude, Altitude, SpeedStr, CntOfSatFix);
        cm_sys_log("GNSS getlocateinfo:%s, %s, %s, %s, %s\n", Longitude, Latitude, Altitude, SpeedStr, CntOfSatFix);
    }
    else
    {
        cm_printf("GNSS NO SINGAL\n");
    }
    
    free(Longitude);
    free(Latitude);
    free(Altitude);
    free(SpeedStr);
    free(CntOfSatFix);

    return;
}

void cm_test_gnss_getrawdata(void)
{
    char *rawdata = (char *)malloc(1024);
    if (rawdata == NULL)
    {
        return;
    }
    memset(rawdata, 0, sizeof(rawdata));

    cm_gnss_getrawdata(rawdata);
    cm_printf("GNSS getrawdata:%s\n", rawdata);
    cm_sys_log("GNSS getrawdata:%s", rawdata);

    free(rawdata);

    return;
}

#endif